package oop2.Task;

import java.util.Scanner;

public class post_baccalaureate_class {         //学士后班级
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        post_baccalaureate_class a = new post_baccalaureate_class();
        a.name = "学士后87班";
        a.teacher = "张老师";
        a.date = "2022年5月8日";
        int choice = 0;
        while (true) {
            System.out.println("1:查看班级信息，2:添加新学生，3:得到班级总人数，4:退出");
            choice = input.nextInt();
            if (choice == 1) {
                System.out.println("--查看班级信息--");
                a.showCisInfo();
            } else if (choice == 2) {
                System.out.println("--添加新学生--");
                System.out.print("输入添加新学生的姓名:");
                String stuName = input.next();
                a.addNewStu(stuName);
            } else if (choice == 3) {
                System.out.println("--得到班级总人数--");
                System.out.println(a.name + "班级总人数为" + a.getStudentNumber());
            } else if (choice == 4) {
                System.out.println("退出");
                break;
            }
        }
    }

    String name;    //班级名称
    String teacher; //老师姓名
    String date;    //开班日期
    String[] stus = new String[35];
    int index = 0;

    public void showCisInfo() {
        System.out.println("班级名称:" + name + "，指导老师:" + teacher);
        System.out.println("开班日期:" + date);
        System.out.println("班级学生信息为:");
        for (int i = 0; i <= index; i++)
            System.out.print(stus[i] + " ");
        System.out.println();
    }

    public void addNewStu(String stuNmae) {
        for (int i = 0; i < stus.length; i++) {
            if (stus[i] != null && stus[i].equals(stuNmae)) { //防止空指针异常
                System.out.println("名字重复,不能添加");
                return;
            }
            if (stus[i] == null) {
                stus[i] = stuNmae;
                index = i;
                return;
            }
        }
    }

    public int getStudentNumber() {
        return index + 1;
    }

}
